package com.hbt.yiqing.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hbt.yiqing.R;
import com.hbt.yiqing.adapter.RecChinaAdapter;
import com.hbt.yiqing.entity.YQInfo;
import com.hbt.yiqing.utils.DataUtils;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ProvinceActivity extends AppCompatActivity {

    @BindView(R.id.confirm_sort)
    TextView confirmSort;
    @BindView(R.id.curConfirm_sort)
    TextView curConfirmSort;
    @BindView(R.id.suspect_sort)
    TextView suspectSort;
    @BindView(R.id.heal_sort)
    TextView healSort;
    @BindView(R.id.dead_sort)
    TextView deadSort;
    @BindView(R.id.recycle)
    RecyclerView recycle;
    private RecChinaAdapter recChinaAdapter;
    boolean confirm_asc = true;
    boolean cur_confirm_asc= true;
    boolean suspect_asc = true;
    boolean heal_asc = true;
    boolean dead_asc = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_province);
        ButterKnife.bind(this);
        initRecycler();
    }

    private void initRecycler() {
        //为recycle设置布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycle.setLayoutManager(layoutManager);
        recChinaAdapter = new RecChinaAdapter(DataUtils.getChina().getChildren());
        recycle.setAdapter(recChinaAdapter);
    }


    @OnClick({R.id.confirm_sort, R.id.curConfirm_sort, R.id.suspect_sort, R.id.heal_sort, R.id.dead_sort})
    public void onViewClicked(View view) {
        List<YQInfo> yqInfoss = null;
        yqInfoss = recChinaAdapter.getInfos();
        if (yqInfoss!=null){
            switch (view.getId()) {
                case R.id.confirm_sort:
                    confirm_asc = confirm_asc?false:true;
                    Collections.sort(yqInfoss, new Comparator<YQInfo>() {
                        @Override
                        public int compare(YQInfo o1, YQInfo o2) {
                            return confirm_asc?o1.getConfirm()-o2.getConfirm():o2.getConfirm()-o1.getConfirm();
                        }
                    });
                    break;
                case R.id.curConfirm_sort:
                    cur_confirm_asc = cur_confirm_asc?false:true;
                    Collections.sort(yqInfoss, new Comparator<YQInfo>() {
                        @Override
                        public int compare(YQInfo o1, YQInfo o2) {
                            return cur_confirm_asc?o1.getNowConfirm()-o2.getNowConfirm():o2.getNowConfirm()-o1.getNowConfirm();
                        }
                    });
                    break;
                case R.id.suspect_sort:
                    suspect_asc = suspect_asc?false:true;
                    Collections.sort(yqInfoss, new Comparator<YQInfo>() {
                        @Override
                        public int compare(YQInfo o1, YQInfo o2) {
                            return suspect_asc?o1.getSuspect()-o2.getSuspect():o2.getSuspect()-o1.getSuspect();
                        }
                    });
                    break;
                case R.id.heal_sort:
                    heal_asc = heal_asc?false:true;
                    Collections.sort(yqInfoss, new Comparator<YQInfo>() {
                        @Override
                        public int compare(YQInfo o1, YQInfo o2) {

                            return heal_asc?o1.getHeal()-o2.getHeal():o2.getHeal()-o1.getHeal();
                        }
                    });
                    break;
                case R.id.dead_sort:
                    dead_asc = dead_asc?false:true;
                    Collections.sort(yqInfoss, new Comparator<YQInfo>() {
                        @Override
                        public int compare(YQInfo o1, YQInfo o2) {
                            return dead_asc?o1.getDead()-o2.getDead():o2.getDead()-o1.getDead();
                        }
                    });
                    break;
            }//switch end
            recChinaAdapter.notifyDataSetChanged();
        }//if end

    }//onViewClicked end (sort end)
}
